package cn.honglian.user.dto;


import cn.honglian.basic.util.MD5Utils;
import cn.honglian.basic.util.StrUtils;
import cn.honglian.user.domain.User;
import lombok.Data;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Data
public class RegisterEmailDto {

    @NotNull(message = "邮箱不能为空")
    @Email
    private String email;
    @NotNull(message = "图片验证码不能为空")
    private String imageCodeValue;
    @NotNull(message = "短信验证码不能为空")
    private String emailCodeValue;
    @NotNull(message = "密码不能为空")
    private String emailPassword;
    @NotNull(message = "二次密码不能为空")
    private String emailPasswordRepeat;

    public User getUser(){
        String salt = StrUtils.getComplexRandomString(32);
        String password = MD5Utils.encrypByMd5(salt + this.emailPassword);
        return User.builder()
                .username(this.email)
                .email(this.email)
                .password(password)
                .salt(salt)
                .createtime(new Date())
                .state(0)
                .build();
    }
}
